
package com.booking.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;

import com.booking.R;
import com.booking.utils.InterfaceHelper.HomeActionListener;

/**
 * @author iholub May 22, 2013
 */
public class HomeFragment extends BasicFragment implements OnClickListener {
    private HomeActionListener mHomeActionListener;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.layout_home, container, false);

        Button places = (Button) view.findViewById(R.id.choose_place);
        Button services = (Button) view.findViewById(R.id.choose_service);
        Button favorites = (Button) view.findViewById(R.id.favorites);

        places.setOnClickListener(this);
        services.setOnClickListener(this);
        favorites.setOnClickListener(this);

        return view;
    }

    @Override
    public void updateData() {
    }

    @Override
    public FragmentType getFragmentType() {
        return FragmentType.HOME;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        try {
            mHomeActionListener = (HomeActionListener) activity;
        } catch (ClassCastException e) {
            e.printStackTrace();
        }

    }

    @Override
    public void onDetach() {
        super.onDetach();
        mHomeActionListener = null;
    }

    @Override
    public void onClick(View v) {
        FragmentType fragmentType = null;
        switch (v.getId()) {
            case R.id.choose_place:
                fragmentType = FragmentType.PLACES_CONTAINER;
                break;
            case R.id.choose_service:
                fragmentType = FragmentType.SERVICES_LIST;
                break;
            case R.id.favorites:
                fragmentType = FragmentType.FAVORITE;
                break;

            default:
                break;
        }

        if (fragmentType != null && mHomeActionListener != null) {
            mHomeActionListener.onShowFragment(fragmentType);
        }
    }
}
